package Leetcode第一期;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * @author : K k
 * @date : 19:18 2020/9/6
 * 双栈实现队列
 */
public class QueueCustom<T> {
    private Stack<T> input;
    private Stack<T> output;

    public QueueCustom(){
        this.input=new Stack<>();
        this.output=new Stack<>();
    }

    public boolean add(T t){
        if(t==null) {
            return false;
        }
        input.push(t);
        return true;
    }

    public T pop() {
        if (!output.isEmpty()){
            return output.pop();
        }else {
            while (!input.isEmpty()){
                output.push(input.pop());
            }
            return output.pop();
        }
    }

    public T peek() {
        if (!output.isEmpty()){
            return output.peek();
        }else {
            while (!input.isEmpty()){
                output.push(input.pop());
            }
            return output.peek();
        }
    }

    public boolean isEmpty() {
        return output.isEmpty()&&input.isEmpty();
    }
    public static void main(String[] args) {
        Queue<Integer> queue=new LinkedList();
        queue.poll();
        queue.peek();
    }
}
